# Contributor: Eric Molitor <eric@molitor.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Maintainer:
# this is a temp hack package for zig that depends on lld15-libs
pkgname=lld15
pkgver=15.0.7
pkgrel=5
pkgdesc="The LLVM Linker"
url="https://llvm.org/"
# for zig only
# and firefox
arch="aarch64 armv7 ppc64le x86 x86_64 riscv64"
license="Apache-2.0"
makedepends="
	cmake
	compiler-rt
	libedit-dev
	llvm15-dev
	llvm15-static
	llvm-libunwind-dev
	patchelf
	samurai
	zlib-dev
	"
subpackages="$pkgname-libs $pkgname-dev"
source="https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/lld-$pkgver.src.tar.xz
	https://github.com/llvm/llvm-project/releases/download/llvmorg-$pkgver/cmake-$pkgver.src.tar.xz
	cxx17.patch
	"
builddir="$srcdir/lld-$pkgver.src"
# already works, temp package for zig only
options="!check"

replaces="lld-libs"

case "$CARCH" in
armhf)
	# for some reason they hang forever, but the actual linker works fine
	options="$options !check"
	;;
esac

build() {
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_MODULE_PATH="$srcdir/cmake-$pkgver.src/Modules" \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DBUILD_SHARED_LIBS=ON \
		-DLLVM_INCLUDE_TESTS=OFF \
		-DLLD_BUILT_STANDALONE=ON
	cmake --build build
}

package() {
	depends="!lld"
	DESTDIR="$pkgdir" cmake --install build

	# see main/lld
	case "$CARCH" in
	riscv64)
		;;
	*)
		patchelf --add-needed libscudo.so "$pkgdir"/usr/bin/lld
		;;
	esac
}

sha512sums="
5dc0690c1eb3c37ee29c4add65a08f7b93ce1363cf9099243c9dc1124d1ca77fe19bbf24dad3984de4553eda716f706d49dff63461b709bec6645272e67f0178  lld-15.0.7.src.tar.xz
85097a6eaee0df004567905f7e5ce8ca02e3b46c6fc66fa552fe99734642e6ee61685de4e5e6e8b505963334d7b91d98ecd9c5870e6bdd3f0018ee5b963ffa96  cmake-15.0.7.src.tar.xz
731077024624650bfb62341bdc380bc98ccfb690a462436cdfa272f90f590dfb75c06d066baa9a256438716eda1d5996c2d0b66c3fc95f151131aa1a843245e8  cxx17.patch
"
